package com.server.llh.llhserverwork.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.bean.MyAddress;

import java.util.ArrayList;
import java.util.List;


public class LlhAddressItemAdapter extends BaseAdapter {

    public List<MyAddress> getObjects() {
        return objects;
    }

    public void setObjects(List<MyAddress> objects) {
        this.objects = objects;
    }

    private List<MyAddress> objects = new ArrayList<MyAddress>();

    private Context context;
    private LayoutInflater layoutInflater;

    public LlhAddressItemAdapter(Context context,List<MyAddress> objects ) {
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
        this.objects=objects;
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public MyAddress getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.llh_address_item, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((MyAddress)getItem(position), (ViewHolder) convertView.getTag());
        return convertView;
    }

    private void initializeViews(MyAddress object, ViewHolder holder) {
        //TODO implement
        holder.addressTxt.setText(object.getAddress());
        holder.userNameTxt.setText(object.getUserName());
        holder.userPhoneTxt.setText(object.getAddressPhone());
    }

    protected class ViewHolder {
        private LinearLayout showAddressAll;
    private RelativeLayout addressContent;
    private TextView addressTxt;
    private TextView userNameTxt;
    private TextView userPhoneTxt;
    private ImageView imageBreak;

        public ViewHolder(View view) {
            showAddressAll = (LinearLayout) view.findViewById(R.id.show_address_all);
            addressContent = (RelativeLayout) view.findViewById(R.id.address_content);
            addressTxt = (TextView) view.findViewById(R.id.addressTxt);
            userNameTxt = (TextView) view.findViewById(R.id.userNameTxt);
            userPhoneTxt = (TextView) view.findViewById(R.id.userPhoneTxt);
            imageBreak = (ImageView) view.findViewById(R.id.image_break);
            imageBreak.setVisibility(View.INVISIBLE);
        }
    }
}
